<?php

/**
 * Class SMSService
 */
header("Content-Type:text/html;charset=utf-8");
include_once("./resource/SDK/YunpianAutoload.php");
class SMSService extends BaseService
{
    private static $self = NULL;

    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }

        return self::$self;
    }

    public function SendSMS($mobile,$news_captcha)
    {

        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取

        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1690598','tpl_value'=>('#code#').'='.urlencode($news_captcha),'apikey'=>$apikey,'mobile'=>$mobile);
        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
        $array = json_decode($json_data,true);
        return $array;
        curl_close($ch);

    }

    /**
     * 注册短信通知
     * @param $red
     * @param $amount
     * @param $ticket
     * @param $mobile
     */
    public function RegisterSMS($red,$amount,$ticket,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692474','tpl_value'=>('#red#').'='.urlencode($red).'&'.urlencode('#amount#').'='.urlencode($amount).'&'.urlencode('#ticket#').'='.urlencode($ticket),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }



    /**
     * 红包短信通知
     * @param $red
     * @param $time
     * @param $mobile
     */
    public function RedSMS($red,$time,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692492','tpl_value'=>('#red#').'='.urlencode($red).'&'.urlencode('#time#').'='.urlencode($time),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }


    /**
     * 红包过期短信通知
     * @param $red
     * @param $mobile
     */
    public function RedDueSMS($red,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692488','tpl_value'=>('#red#').'='.urlencode($red),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }

    /**
     * 项目回款短信通知
     * @param $time
     * @param $item
     * @param $amount
     */
    public function ItemReturnSMS($time,$item,$amount,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692496','tpl_value'=>('#time#').'='.urlencode($time).'&'.urlencode('#item#').'='.urlencode($item).'&'.urlencode('#amount#').'='.urlencode($amount),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }


    /**
     * 提现短信通知
     * @param $time
     * @param $amount
     */
    public function CashSMS($time,$amount,$bank,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692484','tpl_value'=>('#time#').'='.urlencode($time).'&'.urlencode('#amount#').'='.urlencode($amount).'&'.urlencode('#bank#').'='.urlencode($bank),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }

    /**
     * 交易密码短信通知
     * @param $time
     * @param $mobile
     */
    public function UpPwdSMS($time,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692476','tpl_value'=>('#time#').'='.urlencode($time),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }


    /**
     * 投资短信通知
     * @param $time
     * @param $item
     * @param $amount
     * @param $mobile
     */
    public function InvestSMS($time,$item,$amount,$mobile)
    {
        $apikey = "09f54ac14224cc8b4d45e8031412f48e"; //修改为您的apikey(https://www.yunpian.com)登录官网后获取
        $ch = curl_init();
        /* 设置验证方式 */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
        /* 设置返回结果为流 */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        /* 设置超时时间*/
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        /* 设置通信方式 */
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        // 需要对value进行编码
        $data=array('tpl_id'=>'1692480','tpl_value'=>('#time#').'='.urlencode($time).'&'.urlencode('#item#').'='.urlencode($item).'&'.urlencode('#amount#').'='.urlencode($amount),'apikey'=>$apikey,'mobile'=>$mobile);

        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            return curl_exec($ch);
        }
        $json_data = tpl_send($ch,$data);
//        $array = json_decode($json_data,true);
//        return $array;
        curl_close($ch);
    }
}
?>






